package com.team.engine.util;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.Reader;

import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;

public class STAXTest {
	
	public static void main(String[] args) {
		XMLInputFactory factory = XMLInputFactory.newInstance();
		XMLStreamReader readerXML = null;
		File file = new File("d:\\test.xml");
		
		try {
			Reader fileReader = new FileReader(file); 
			readerXML = factory.createXMLStreamReader(fileReader);
			int eventType = -1;
			while(readerXML.hasNext()){
				eventType = readerXML.next();
				if(eventType == readerXML.START_ELEMENT){
					if(readerXML.getLocalName().equals("person")){
//						while(readerXML.nextTag()==readerXML.START_ELEMENT){
//							System.out.println("=====");
//							System.out.println(readerXML.);
//							if(readerXML.getLocalName().equals("name"))
//								System.out.println(readerXML.getElementText());
//						}
//						if(readerXML.nextTag()==readerXML.START_ELEMENT)
//							System.out.println(readerXML.getElementText());
					}
					if(readerXML.getLocalName().equals("name"))
						System.out.println(readerXML.getElementText());
					if(readerXML.getLocalName().equals("hotel"))
						System.out.println(readerXML.getElementText());
				}
			}
		} catch (XMLStreamException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
